FROM centos:7

MAINTAINER Yang <yangyufans@qq.com>

ENV REDIS_VERSION=4.0.10

RUN yum install -y wget gcc make which zlib-devel openssl-devel
RUN cd / && wget https://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.0.tar.gz \
    && tar -zvxf ruby-2.6.0.tar.gz \
    && rm -rf ruby-2.6.0.tar.gz \
    && cd /ruby-2.6.0 \
    && ./configure  \
    && make && make install

RUN cd /ruby-2.6.0/ext/zlib \
    && ruby extconf.rb \
    && sed -i 's/$(top_srcdir)/..\/..\//' Makefile \
    && make && make install

RUN cd /ruby-2.6.0/ext/openssl \
    && ruby extconf.rb  --with-openssl-include=/usr/local/openssl/include/ --with-openssl-lib=/usr/local/openssl/lib \
    && sed -i 's/$(top_srcdir)/..\/..\//' Makefile \
    && make && make install


RUN gem install redis

RUN cd / && wget http://download.redis.io/releases/redis-$REDIS_VERSION.tar.gz \
 && tar -zxvf redis-$REDIS_VERSION.tar.gz \
 && rm -rf redis-$REDIS_VERSION.tar.gz \
 && cd /redis-$REDIS_VERSION \
 && make MALLOC=libc \
 && make install \
 && cp /redis-$REDIS_VERSION/redis.conf /usr/local/bin/ \
 && cd /

RUN mkdir /redis /redis/conf /redis/logs /redis/data

RUN sed -i 's/logfile ""/logfile "\/redis\/logs\/redis.log"/' /usr/local/bin/redis.conf && \
    sed -i 's/bind 127.0.0.1/#bind 127.0.0.1/' /usr/local/bin/redis.conf && \
    sed -i 's/dir .\//dir \/redis\/data\//' /usr/local/bin/redis.conf

RUN echo "ZONE=Asia/Shanghai" > /etc/sysconfig/clock && \
    rm -rf /etc/localtime && \
    ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

COPY start.sh /

RUN chmod 777 /start.sh

EXPOSE 6379 16379

ENTRYPOINT ["/start.sh"]
